home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 1 / Gekikoh Dennoh Club Vol. 1 (Japan).7z / Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin / kowin / archive / net / chatwins.lzh / chatwinm.c < prev    next >
C/C++ Source or Header  |  1995-11-23  |  5KB  |  241 lines

  1. /*    Copyright 1993 H.Ogasawara (COR.)    */
  2.  
  3. #include    <corlib.h>
  4.  
  5. #define        MAXCHAR        160
  6. #define        FONT        12
  7. #define        Ctrl(a)        ((a)&0x1f)
  8.  
  9. short    font= FONT,
  10.     fontx= FONT/2,
  11.     attr= 9,
  12.     attrN= 9,
  13.     attrF= 11,
  14.     crmode= 1;
  15. int    usercode= UserPaste;
  16. short    maxchar= MAXCHAR;
  17. int    WindowHeapSize= 1024*8;
  18. char    progname[30],
  19.     header[30];
  20.  
  21. static char    *username[]= {
  22.         "UserPaste", "UserString", "UserStrings", "UserSheet" };
  23.  
  24. send_k20string( msg, cr )
  25. char    *msg;
  26. {
  27.     EventInfo    info;
  28.     if( cr )
  29.         strcat( msg, "\r\0Copyright 1993-94 H.Ogasawara (COR.)" );
  30.     info.option= EventUser;
  31.     info.ComData= usercode;
  32.     info.ComBuffer= msg;
  33.     PidSendEvent( progname, &info, TRUE );
  34. }
  35.  
  36. pos_set( wp, input )
  37. WindowID    wp;
  38. InputClass    *input;
  39. {
  40.     int    x, y, h;
  41.     int    cur= InputGetCursor(input)*fontx;
  42.     WindowGetHome( wp, &x, &y );
  43.     WindowGetViewSize( wp, &h, &y );
  44.     if( cur >= x+h-font ){
  45.         WindowScroll( wp, cur-x-h+12+8*fontx, 0 );
  46.         return    TRUE;
  47.     }else if( cur < x ){
  48.         WindowScroll( wp, cur-x-8*fontx, 0 );
  49.         return    TRUE;
  50.     }
  51.     return    FALSE;
  52. }
  53.  
  54. init_input( wp, ibuf, input )
  55. WindowID    wp;
  56. char    *ibuf;
  57. InputClass    *input;
  58. {
  59.     strcpy( ibuf, header );
  60.     InputSet( input, 0, 0, ibuf, maxchar, attr, font );
  61.     golast_input( wp, ibuf, input );
  62. }
  63.  
  64. golast_input( wp, ibuf, input )
  65. WindowID    wp;
  66. char        *ibuf;
  67. InputClass    *input;
  68. {
  69.     InputSetCursor( input, strlen( ibuf ) );
  70.     if( !pos_set( wp, input ) )
  71.         input_redraw( wp, input );
  72. }
  73.  
  74. input_redraw( wp, input )
  75. WindowID    wp;
  76. InputClass    *input;
  77. {
  78.     DrawBuf    dbuf[20];
  79.     DrawSetClear( dbuf, attr&AttrReverse?attr&3:0 );
  80.     WindowDraw( wp, dbuf, 1+InputSetDraw( dbuf+1, input ) );
  81. }
  82.  
  83. Exec( wp, info )
  84. WindowID    wp;
  85. EventInfo    *info;
  86. {
  87.     DrawBuf        dbuf[20];
  88.     static InputClass    input;
  89.     static char    ibuf[MAXCHAR+4];
  90.     static short    histflag= FALSE;
  91.     int    i;
  92.     switch( info->option ){
  93.     case EventOpen:
  94.         init_input( wp, ibuf, &input );
  95.         return    FALSE;
  96.     case EventRedraw:
  97.         input_redraw( wp, &input );
  98.         return    TRUE;
  99.     case EventMouseSwitch:
  100.         if( info->LeftON ){
  101.             SendData( WindowGetParent(wp), info, UserString, ibuf );
  102.             return    TRUE;
  103.         }
  104.         break;
  105.     case EventMouseEnter:
  106.     case EventMouseOut:
  107.         attr= ( info->option == EventMouseEnter ) ? attrF:attrN ;
  108.         input.attr= attr;
  109.         WindowDraw( wp, dbuf, InputSetCursorVisible( dbuf, &input,
  110.                 info->option == EventMouseEnter ) );
  111.         input_redraw( wp, &input );
  112.         return    TRUE;
  113.     case EventKey:
  114.         i= 0;
  115.         switch( info->KeyCode ){
  116.         case Ctrl('e'):
  117.             if( InputGetMode() )
  118.                 goto    Nfunc;
  119.             goto    up_history;
  120.         case Ctrl('p'):
  121.             if( !InputGetMode() )
  122.                 goto    Nfunc;
  123.         case FuncKeyRollDown:
  124.         case Ctrl('w'):
  125.         up_history:
  126.             i= 1;
  127.         case FuncKeyRollUp:
  128.         case Ctrl('x'):
  129.         case Ctrl('n'):
  130.             getnexthist( ibuf, histflag, i );
  131.             golast_input( wp, ibuf, &input );
  132.             histflag= TRUE;
  133.             return    TRUE;
  134.         case '\r':
  135.             i= crmode;
  136.         case '\n': {
  137.             int    x, y;
  138.             histflag= FALSE;
  139.             addhist( ibuf );
  140.             send_k20string( ibuf, i );
  141.             init_input( wp, ibuf, &input );
  142.             WindowGetHome( wp, &x, &y );
  143.             if( x )
  144.                 WindowScroll( wp, -maxchar*fontx+100, 0 );
  145.             }
  146.             return    TRUE;
  147.         default:
  148.             if( info->KeyCode >= FuncKey+1 &&
  149.                     info->KeyCode <= FuncKey+20 ){
  150.                 keyinput( wp, info->KeyCode-FuncKey-1 );
  151.                 return    TRUE;
  152.             }
  153.             histflag= FALSE;
  154.         case Ctrl('a'):
  155.         case Ctrl('q'):
  156.         Nfunc:
  157.             WindowDraw( wp, dbuf,
  158.                 InputKey( dbuf, &input, info->KeyCode,
  159.                             info->ShiftStat ) );
  160.             pos_set( wp, &input );
  161.         }
  162.         return    TRUE;
  163.     }
  164.     return    FALSE;
  165. }
  166.  
  167.  
  168. WindowMain( argc, argv )
  169. char    **argv;
  170. {
  171.     int    i;
  172.     char    *title= "ChatWinM v1.21.1";
  173.     strcpy( progname, "k20.win" );
  174.     *header= '\0';
  175.     for( i= 0 ; i< argc ; i++ ){
  176.         if( *(argv[i]) == '-' ){
  177.             switch( argv[i][1] ){
  178.             case 't':
  179.                 title= argv[i]+2;
  180.                 break;
  181.             case 'c':
  182.                 crmode= 0;
  183.                 break;
  184.             case 'a':
  185.                 attrN= atoi2( argv[i]+2 );
  186.                 break;
  187.             case 'A':
  188.                 attrF= atoi2( argv[i]+2 );
  189.                 break;
  190.             case 'm':
  191.                 strcpy( header, argv[i]+2 );
  192.                 break;
  193.             case 'p':
  194.                 strcpy( progname, argv[i]+2 );
  195.                 break;
  196.             case 'r':
  197.                 if( !read_fncfile( argv[i]+2 ) ){
  198.                     ConsoleOpen();
  199.                     ConsolePrint( "chatwin:ファンクションキーファイルが読めません\r\n" );
  200.                 }
  201.                 break;
  202.             case 'f':
  203.                 fontx= (font= atoi2(argv[i]+2))/2;
  204.                 if( fontx == 5 )
  205.                     maxchar= MAXCHAR;
  206.                 else if( fontx == 12 )
  207.                     maxchar= 82;
  208.                 else if( fontx == 8 )
  209.                     maxchar= 120;
  210.                 else
  211.                     maxchar= MAXCHAR/*,
  212.                     fontx= (font= FONT)/2*/;
  213.                 break;
  214.             case 'u':
  215.                 {
  216.                 int    j;
  217.                 char    *p= argv[i]+2;
  218.                 for( j= 0 ; j< 4 ; j++ ){
  219.                     if( !strcmp(p,username[j]) ){
  220.                         usercode= j;
  221.                         break;
  222.                     }
  223.                 }
  224.                 if( j == 4 ){
  225.                     if( *p >= '0' && *p <= '9' )
  226.                         usercode= atoi2(p);
  227.                     else for( usercode= 0 ; *p ;
  228.                         usercode<<=8,
  229.                         usercode+= *p++ );
  230.                 }
  231.                 }
  232.                 break;
  233.             }
  234.         }
  235.     }
  236.     attr= attrN;
  237.     MgWindowScrollOpenArgs( 100, 100, 80*6+14, 14+font, title,
  238.         argc, argv, maxchar*fontx, font, Icon|Zoom|MgSwitchHV, Exec );
  239. }
  240.  
  241.